﻿using System;
using System.Linq;
using Sumen.Business;
using Sumen.Business.Permission;
using Sumen.Business.Presenter.Category;
using Sumen.Business.Presenter.Inventory;
using Sumen.Library.Enum;
using Sumen.Library.Froms;


namespace Sumen.GUI.Inventory
{
    public partial class Frm_General_Inventory : XtraUserControlKira
    {
        private EnumFormCode _fromCode = EnumFormCode.FrmGeneralInventory;
        #region Presenter

        private StockPresenter _stockPresenter;
        private InventoryPresenter _inventoryPresenter;

        #endregion


        #region Form

        public Frm_General_Inventory()
        {
            InitializeComponent();
            buttonsArray1.capQuyen(new Permission(_fromCode.ToString(), ClsPublic.User.User_Username));
            _stockPresenter = new StockPresenter();
            _inventoryPresenter = new InventoryPresenter();

            DateTime begin = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DateTime end = begin.AddMonths(1).AddMinutes(-1);
            dateBegin.DateTime = begin;
            dateEnd.DateTime = end;
            //if (ClsPublic.SYSTEM_WRITELOG == "1")
            //{
            //    SysLogPresenter log = new SysLogPresenter();
            //    log.Add(_fromCode, EnumFormStatus.View, "", "");
            //}
        }

        private void Frm_General_Inventory_Load(object sender, EventArgs e)
        {
            LoadForm();
        }

        #endregion

        #region Button event

        private void cmbThang_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cmbThang.SelectedIndex)
            {
                case 0:
                    //        Hôm nay
                    dateBegin.DateTime = DateTime.Today;
                    dateEnd.DateTime = DateTime.Today.AddDays(1).AddMinutes(-1);
                    break;
                case 1:
                    //Tuần này
                    int ab = (int)DateTime.Today.DayOfWeek - 1;
                    dateBegin.DateTime = DateTime.Today.AddDays(-ab);
                    dateEnd.DateTime = dateBegin.DateTime.AddDays(7).AddMinutes(-1);
                    break;
                case 2:
                    //Tháng này
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 3:
                    //Quý này

                    break;
                case 4:
                    //Quý 1
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 1, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(3).AddMinutes(-1);
                    break;
                case 5:
                    //Quý 2
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 4, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(3).AddMinutes(-1);
                    break;
                case 6:
                    //Quý 3
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 7, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(3).AddMinutes(-1);
                    break;
                case 7:
                    //Quý 4
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 10, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(3).AddMinutes(-1);
                    break;
                case 8:
                    //Năm này
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 1, 1);
                    dateEnd.DateTime = new DateTime(DateTime.Now.Year, 12, 31);
                    break;
                case 9:
                    //Tháng 1
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 1, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 10:
                    //Tháng 2
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 2, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 11:
                    //Tháng 3
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 3, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 12:
                    //Tháng 4
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 4, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 13:
                    //Tháng 5
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 5, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 14:
                    //Tháng 6
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 6, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 15:
                    //Tháng 7
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 7, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 16:
                    //Tháng 8
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 8, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 17:
                    //Tháng 9
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 9, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 18:
                    //Tháng 10
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 10, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 19:
                    //Tháng 11
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 11, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
                case 20:
                    //Tháng 12
                    dateBegin.DateTime = new DateTime(DateTime.Now.Year, 12, 1);
                    dateEnd.DateTime = dateBegin.DateTime.AddMonths(1).AddMinutes(-1);
                    break;
            }
        }

        #endregion


        #region Method

        public override void LoadForm()
        {
            LoadStock();
            gridControl1.DataSource = _inventoryPresenter.GetGeneralInventory(lookUpStock.EditValue + string.Empty, dateBegin.DateTime, dateEnd.DateTime).First();
            bandedGridView1.ExpandAllGroups();
            bandedGridView1.BestFitColumns();
        }

        void LoadStock()
        {
            lookUpStock.Properties.DataSource = _stockPresenter.GetAll();
        }

        #endregion

        private void buttonsArray1_btnEventClose_click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void buttonsArray1_btnEventExcel_click(object sender, EventArgs e)
        {

        }

        private void buttonsArray1_btnEventPrint_click(object sender, EventArgs e)
        {

        }

        private void buttonsArray1_btnEventProduceReports_click(object sender, EventArgs e)
        {
            LoadForm();
        }










    }
}